import { post } from '../utils/request'

interface uploadResult {
  created_at: string;
  // 上传文件的唯一标识 类似MD5
  etag: string;
  file_class: string;
  file_name: string;
  file_size: number;
  file_type: string;
  // web_url
  file_url: string;
  id: string;
  updated_at: string;
  user_id: string;
  username: string;
}

interface OCRResult {
  code: number;
  log_id: string;
  msg: string;
  output: {
    // 结果坐标
    line_rects: {
      height: number
      width: number
      x: number
      y: number
    }[];
    // 识别结果
    line_texts: string[];
  }
}

// 上传文件接口
export function uploadOcr(data: any) {
  return post<uploadResult>('/api/util/upload/ocr', data, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 识别接口
export function ocrRecognition(data: any) {
  return post<OCRResult>('/api/ocr/scan', data)
}